﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GlxRRSDB.ReportDataSetTableAdapters;
using GlxRRSDB;
using GlxRRSReporter.DailyReporter;
using GlxRRSDB.Data;
using GlxRRSDB.Facades;
using GlxRRSMain.Utils;

namespace GlxRRSMain.UserControls
{
    public partial class DailyRevenueReportControl : UserControl
    {
        public DailyRevenueReportControl()
        {
            InitializeComponent();
        }
        private void DailyRevenueReportControl_Load(object sender, EventArgs e)
        {
            pickerFrom.Value = DateTime.Now;
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            DateTime fromdate = pickerFrom.Value;
            Dictionary<int, DailyReportData> dictAdmission = new Dictionary<int, DailyReportData>();
            Dictionary<int, DailyReportData> dictBO = new Dictionary<int, DailyReportData>();
            Dictionary<int, DailyReportData> dictCO = new Dictionary<int, DailyReportData>();
            Dictionary<int, DailyReportData> dictOccupancy = new Dictionary<int, DailyReportData>();
            //
            DailyReportFacade.getTotalAdmissionEx(pickerFrom.Value, pickerFrom.Value, dictAdmission);
            DailyReportFacade.getTotalBOEx(pickerFrom.Value, pickerFrom.Value, dictBO);
            DailyReportFacade.getTotalCOEx(pickerFrom.Value, pickerFrom.Value, dictCO);
            DailyReportFacade.getTotalOccupancyEx(pickerFrom.Value, pickerFrom.Value, dictOccupancy);
            //
            Dictionary<int, Dictionary<DateTime, DailyReportData>> dictDetailAdmission = new Dictionary<int, Dictionary<DateTime, DailyReportData>>();
            Dictionary<int, Dictionary<DateTime, DailyReportData>> dictDetailBO = new Dictionary<int, Dictionary<DateTime, DailyReportData>>();
            Dictionary<int, Dictionary<DateTime, DailyReportData>> dictDetailCO = new Dictionary<int, Dictionary<DateTime, DailyReportData>>();
            Dictionary<int, Dictionary<DateTime, DailyReportData>> dictDetailFilmAdmission = new Dictionary<int, Dictionary<DateTime, DailyReportData>>();
            Dictionary<int, Dictionary<DateTime, DailyReportData>> dictDetailFilmBO = new Dictionary<int, Dictionary<DateTime, DailyReportData>>();
            //
            DailyReportFacade.getDetailAdmissionWeek(pickerFrom.Value, dictDetailAdmission);
            DailyReportFacade.getDetailBOWeek(pickerFrom.Value, dictDetailBO);
            DailyReportFacade.getDetailCOWeek(pickerFrom.Value, dictDetailCO);
            DailyReportFacade.getDetailFilmAdmissionWeek(pickerFrom.Value, dictDetailFilmAdmission);
            DailyReportFacade.getDetailFilmBOWeek(pickerFrom.Value, dictDetailFilmBO);
            // get current date report
            generateDailyReport(pickerFrom.Value,dictAdmission, dictBO, dictCO, dictOccupancy, dictDetailAdmission, dictDetailBO, dictDetailCO, dictDetailFilmAdmission, dictDetailFilmBO);
        }
        private void generateDailyReport(DateTime d,
            Dictionary<int, DailyReportData> dictAdmission, 
            Dictionary<int, DailyReportData> dictBO, 
            Dictionary<int, DailyReportData> dictCO, 
            Dictionary<int, DailyReportData> dictOccupancy,
            Dictionary<int, Dictionary<DateTime, DailyReportData>> dictDetailAdmission,
            Dictionary<int, Dictionary<DateTime, DailyReportData>> dictDetailBO,
            Dictionary<int, Dictionary<DateTime, DailyReportData>> dictDetailCO,
            Dictionary<int, Dictionary<DateTime, DailyReportData>> dictDetailFilmAdmission,
            Dictionary<int, Dictionary<DateTime, DailyReportData>> dictDetailFilmBO)
        {
            DailyReporter.init(FileHelper.getDailyReportTemplate(),FileHelper.genDailyReportOut());
            DailyReporter.generateDailyReport(d, dictAdmission, dictBO, dictCO, dictOccupancy,
                dictDetailAdmission, dictDetailBO, dictDetailCO, dictDetailFilmAdmission, dictDetailFilmBO);
        }
    }
}

